<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@page import="org.springframework.web.context.WebApplicationContext"%>
<%@page import="org.springframework.web.context.support.WebApplicationContextUtils"%>
<%@page import="db.AuthorityDAO"%>
<%@page import="db.Authority"%>
<%@ include file="/jsp/common/utility/logined.jsp" %>
<%
	WebApplicationContext ctx = WebApplicationContextUtils.getWebApplicationContext(getServletContext());
	AuthorityDAO authorityDao = (AuthorityDAO)ctx.getBean("AuthorityDAO");
	
	String uid_str = request.getParameter("uid");
	Integer uid_int = 0;
	try{
		uid_int = Integer.parseInt(uid_str);
	}catch(Exception e){
		pageContext.forward("/index.jsp");
		return;
	}
	
	String[] model1 = request.getParameterValues("model1");
	if(model1 != null)
	for(int i=0;i<model1.length;i++){
		Authority authority = new Authority();
		authority.setModule1(1);
		authority.setModule2(Integer.parseInt(model1[i]));
		authority.setUserId(uid_int);
		authorityDao.save(authority);
	}
	
	String[] model2 = request.getParameterValues("model2");
	if(model2 != null)
	for(int i=0;i<model2.length;i++){
		Authority authority = new Authority();
		authority.setModule1(2);
		authority.setModule2(Integer.parseInt(model2[i]));
		authority.setUserId(uid_int);
		authorityDao.save(authority);
	}
	
	String[] model3 = request.getParameterValues("model3");
	if(model3 != null)
	for(int i=0;i<model3.length;i++){
		Authority authority = new Authority();
		authority.setModule1(3);
		authority.setModule2(Integer.parseInt(model3[i]));
		authority.setUserId(uid_int);
		authorityDao.save(authority);
	}
	
	String[] model4 = request.getParameterValues("model4");
	if(model4 != null)
	for(int i=0;i<model4.length;i++){
		Authority authority = new Authority();
		authority.setModule1(4);
		authority.setModule2(Integer.parseInt(model4[i]));
		authority.setUserId(uid_int);
		authorityDao.save(authority);
	}
	
	String[] model5 = request.getParameterValues("model5");
	if(model5 != null)
	for(int i=0;i<model5.length;i++){
		Authority authority = new Authority();
		authority.setModule1(5);
		authority.setModule2(Integer.parseInt(model5[i]));
		authority.setUserId(uid_int);
		authorityDao.save(authority);
	}
	
	String[] model6 = request.getParameterValues("model6");
	if(model6 != null)
	for(int i=0;i<model6.length;i++){
		Authority authority = new Authority();
		authority.setModule1(6);
		authority.setModule2(Integer.parseInt(model6[i]));
		authority.setUserId(uid_int);
		authorityDao.save(authority);
	}
	
	String[] model7 = request.getParameterValues("model7");
	if(model7 != null)
	for(int i=0;i<model7.length;i++){
		Authority authority = new Authority();
		authority.setModule1(7);
		authority.setModule2(Integer.parseInt(model7[i]));
		authority.setUserId(uid_int);
		authorityDao.save(authority);
	}
	
	String[] model8 = request.getParameterValues("model8");
	if(model8 != null)
	for(int i=0;i<model8.length;i++){
		Authority authority = new Authority();
		authority.setModule1(8);
		authority.setModule2(Integer.parseInt(model8[i]));
		authority.setUserId(uid_int);
		authorityDao.save(authority);
	}
	
	String[] model9 = request.getParameterValues("model9");
	if(model9 != null)
	for(int i=0;i<model9.length;i++){
		Authority authority = new Authority();
		authority.setModule1(9);
		authority.setModule2(Integer.parseInt(model9[i]));
		authority.setUserId(uid_int);
		authorityDao.save(authority);
	}
	
	String[] model10 = request.getParameterValues("model10");
	if(model10 != null)
	for(int i=0;i<model10.length;i++){
		Authority authority = new Authority();
		authority.setModule1(10);
		authority.setModule2(Integer.parseInt(model10[i]));
		authority.setUserId(uid_int);
		authorityDao.save(authority);
	}
	
	request.setAttribute("info","success");
	pageContext.forward("/vm/erp_tpl/adminPer.vm");
%>